#if !defined SeqList_h
#define SeqList_h
#include "user.h"
#include<fstream>
#include<iostream>
using namespace std;
#include<cassert>
const int tinitSie=100;
const int tincrement=20;
template<typename T>
class SeqList{
public:
    SeqList(int sz=tinitSize);
    SeqList(const SeqList<T>&L);
    ~SeqList();
    void createList();
    int size()const;
    int length()const;
    int search(T& x)const;
    int searchBYNUM(string num)const;
    int locate(int i)const;
    bool getData(int i, T& x)const;
    bool setData(int i, T& x)const;
    bool insert(int i, T& x);
    bool append(T& x);
    bool remove(int i, T& x);
    bool isEmpty();
    bool isFull();
    void traverseList();
    SeqList<T>operator=(SeqList<T>&L);
    T& operator[](int i);
    T* begin();
    void readFromFile(char* FileName);
    void writeToFile(char* FileName);
private:
    T * data;
    int listSize;
    int length;
    void resize(int newSize);
};
template<typename T>
SeqList<T>::SeqList(int sz)
{
    if(sz>0)
    {
        listSize=sz; length=0;
        data=sz; length=0;
        data=new T[listSize];
        if(data==nullptr)
        {
             cer<<"存储分配失败!"<<endl;exit(1);
        }

    }
}
template<typename T>
SeqList<t>::SeqList(CONST SeqList<T>&L)
{
    listSize=L.size(); length=L.length();
    data=new T[listSize];
    if(data==nullptr)
    {
  cerr<<"存储分配错误!"<<endl;exit(1);
    }
    T temp;
    for（int i =；i<=length；i++）{  L .getData(i,temp);data[i-1]=temp;}

}
    template<typename T>
    SeqList<T>::~SeqList(){delete[]data;data=nullptr;}
    template<typename T>
    void SeqList<T>::resize(int newSize)
    {
        if(newSize<=0)

         {
             errc<<"无效的数组大小!"<<endl;return
         }
      if(newSize!=listSize)
      {
          T*newSize!=listSize];
      }
if(newarray !=nullptr)
{
    cerr<<"储存分配错误!”<<endl;exit(1);
}
 int n=length;        }
 T* srcptr=data;
 T*destptr=newarray;
 while(n--*destptr++= * srcptr++;)
delete[]data;
data=newarray;listSize=newSize；
{

}
template<typenameT>
int SeqList<T>::search(T&x)const
template<typename T>
int SeqList<T>::searchBYNUM（stringnum）const
{
    for(int i=0;i<length;i++)
    if（data[i].getNum()==x.getNum())return i+1;
    return 0;
}
template<typename T>
int SeqList<T>::locate(int i)const;
//定位 函数,所数退回第101<-1<-length)个表项的位置，否则函数返回o,表示定位失败

else return 01

templatec typename T>

bool BegluistkT>ssinsert(int 1, T6 x)

//将新元素K插人到表中第1(1<-1<-length)个表项之后。函数返回插人成功与否的信息，//若插人成功返回true,否则返回false. 1-0是虚报的，实际上是插人到第1个元素的位置1f(1<1 11 1> length) return false;

if(length-listsize)

resize (llstsize+ Increment);

for(int j=length-1; j>-1-1; j--)

data[J+ 1)-data(j];

datal1-11=x;

length+ + ;

return true;

template< typename T>

bool SeqListsT> ssappend(Th x)

( //将新元素 x插人到表尾。函数返回插人成功的信息,若插人成功返回true;否则返回falseif (1ength= =listsize)

1 resize (1istSize+ tincrement); }

data (1ength]=x;

length++i

return true;

template< typename T>

bool SeqList<T> sscemove(int i, TG x)

( //从表中删除第1(1<-1<= length)个表项，通过引用型参数x返回删除的元素值。//函数返回删除成功与否的信息,若删除成功则返回true,否则返回false

lf(length==0) return false;

1f(1<111 i>length) return false;

x=data[1-1];

for(int j=1; j<length; j++) data[j-1]=data[j]; //依次前移,填补length--;

return true;

template< typename T>

void SeqList<T> ;:createList()

//从标准输人(键盘)逐个输人数据,建立顺序表cout<<"开始建立顺序表，请输人表中元素个数:";cin》> length;

if(length >l1stSize) resize (length);for(int 1≈0; l<1ength; 1++)//定位 函数,所数退回第101<-1<-length)个表项的位置，否则函数返回o,表示定位失败

else return 01

templatec typename T>

bool BegluistkT>ssinsert(int 1, T6 x)

//将新元素K插人到表中第1(1<-1<-length)个表项之后。函数返回插人成功与否的信息，//若插人成功返回true,否则返回false. 1-0是虚报的，实际上是插人到第1个元素的位置1f(1<1 11 1> length) return false;

if(length-listsize)

resize (llstsize+ Increment);

for(int j=length-1; j>-1-1; j--)

data[J+ 1)-data(j];

datal1-11=x;

length+ + ;

return true;

template< typename T>

bool SeqListsT> ssappend(Th x)

( //将新元素 x插人到表尾。函数返回插人成功的信息,若插人成功返回true;否则返回falseif (1ength= =listsize)

1 resize (1istSize+ tincrement); }

data (1ength]=x;

length++i

return true;

template< typename T>

bool SeqList<T> sscemove(int i, TG x)

( //从表中删除第1(1<-1<= length)个表项，通过引用型参数x返回删除的元素值。//函数返回删除成功与否的信息,若删除成功则返回true,否则返回false

lf(length==0) return false;

1f(1<111 i>length) return false;

x=data[1-1];

for(int j=1; j<length; j++) data[j-1]=data[j]; //依次前移,填补length--;

return true;

template< typename T>

void SeqList<T> ;:createList()

cout<<"开始建立顺序表，请输人表中元素个数:";cin》> length;

if(length >l1stSize) resize (length);for(int 1=0; l<1ength; 1++)
    cout<< "请输人表中第，

cin>>datalil;r Kfв. B1.mF ,"«cendl,

template< typename T>

void seqList<T> : :traverseList 0

//cout<<"顺序表当前元素最后位置为:

for(int i=0; i<length; itt, ngth 1« endl ;cout<"."<i+ 1«<"

itll+213 10--0) system("pause”);

plate< typename T>

templacestspename

seqList<T> SeqList<T> ::operator- (SeqList<T>6L)

if(&L!-this)

( listSize-L.size0); length=L. lengthl);

data=new T(listSize];

if (data- =nullptr)

cerr«< "f fht néfilil!"ccendl; exit(1); )

for(int i-l; i<-length; i++) ( L,getDatali, temp); datali- lj-temp;

return * this;

template< typename T>

int SeqList<T> ::size() const( return listSize; ) //i@kütüJ thi↑ttemplate< typename T>

int SeqList<T> ::length() const( return length; ) //i@2kK

template< typename T>

bool SeqList<T> ::getData(int i, Ts x) const //l[l38 i↑5iff( if(i>=1 && i<=length)( x=data[i-1]; return true;

else return false;

template< typename T>

bool SeqList<T> : :setData(int i, T6 x)const

( if(i>=1 66 i<=length)( datali-1]=x; return true;

else return false;

template< typename T>cout<< "请输人表中第，

cin>>datalil;r Kfв. B1.mF ,"«cendl,

template< typename T>

void seqList<T> : :traverseList 0

//cout<<"顺序表当前元素最后位置为:

for(int i=0; i<length; itt, ngth 1« endl ;cout<"."<i+ 1«<"

itll+213 10--0) system("pause”);

plate< typename T>

templacestspename

seqList<T> SeqList<T> ::operator- (SeqList<T>6L)

if(&L!-this)

( listSize-L.size0); length=L. lengthl);

data=new T(listSize];

if (data- =nullptr)

cerr«< "f fht néfilil!"ccendl; exit(1); )

for(int i-l; i<-length; i++) ( L,getDatali, temp); datali- lj-temp;

return * this;

template< typename T>

int SeqList<T> ::size() const( return listSize; ) //i@kütüJ thi↑ttemplate< typename T>

int SeqList<T> ::length() const( return length; ) //i@2kK

template< typename T>

bool SeqList<T> ::getData(int i, Ts x) const //l[l38 i↑5iff( if(i>=1 && i<=length)( x=data[i-1]; return true;

else return false;

template< typename T>

bool SeqList<T> : :setData(int i, T6 x)const

( if(i>=1 66 i<=length)( datali-1]=x; return true;

else return false;

template< typename T>
template< typename T>

bool SeqList<T> 1isFull 0)

(return (1ength- - lintsize) 7trueitalse;

template< typename 1

T* SeqList<T> itbegin0)( return datal

template< typename T>

E8EEeam file (FileName, lon:in 1 1oiibinary)it(!rile)

( cout<<" Xf4ITFF il!"<<endl; abort (i;length- o;

length-- ;

file.close();

template< typename T>

void SeqList<T> ::writeToFile (char* FileName)

fstream file (FileName, ios::outlios::binary);

iflfile)

( cout<<" X14TJF 4i!"<<endl; abort();

cout« "tiT l iф .."«< endl;

forlint i-0;i< length;l++) datali].writeToFileifile);file.close();

cout<c"El u и h!"<< endl;

system ("pause") ;

template< typename т>

Ts Seqlist<т>::operator ](int i)(assert(i>-0 &6i< length);

return datali];

, endi ftemplate< typename T>

bool SeqList<T> 1isFull 0)

(return (1ength- - lintsize) 7trueitalse;

template< typename 1

T* SeqList<T> itbegin0)( return datal

template< typename T>

E8EEeam file (FileName, lon:in 1 1oiibinary)it(!rile)

( cout<<" Xf4ITFF il!"<<endl; abort (i;length- o;

length-- ;

file.close();

template< typename T>

void SeqList<T> ::writeToFile (char* FileName)

fstream file (FileName, ios::outlios::binary);

iflfile)

( cout<<" X14TJF 4i!"<<endl; abort();

cout« "tiT l iф .."«< endl;

forlint i-0;i< length;l++) datali].writeToFileifile);file.close();

cout<c"El u и h!"<< endl;

system ("pause") ;

template< typename т>

Ts Seqlist<т>::operator ](int i)(assert(i>-0 &6i< length);

return datali];

# endi f

